#include<iostream>
#include<stdio.h>
using namespace std;
struct ListNode
{
    char data;
    ListNode* next;
};

void CreatList(ListNode* list, char ch[], int n) {
    ListNode* l1 = list;
    for (int i = 0; i < n; ++i) {
        ListNode* node = new ListNode;
        node->data = ch[i];
        node->next = nullptr;
        l1->next = node;
        l1 = l1->next;
    }
}


ListNode* Search(ListNode* list1, int n1, ListNode* list2, int n2) {
    int f = 0, k = 0;
    if (n1 > n2) {
        f = 1;
        k = n1 - n2;
    }
    else 
        k = n2 - n1;

    ListNode* l1 = list1->next, * l2 = list2->next;
    while (k--){
        if (f) l1 = l1->next;
        else l2 = l2->next;
    }

    while (l1 && l2) {
        if (l1->data == l2->data)
            return l1;
        l1 = l1->next;
        l2 = l2->next;
    }
}



int main() {
    ListNode* list1 = new ListNode, *list2 = new ListNode;
    list1->data = ' '; list1->next = nullptr;
    list2->data = ' '; list2->next = nullptr;
    char ch1[7] = { 'l','o','a','d','i','n','g' }, ch2[5] = { 'b','e','i','n','g' };
    CreatList(list1, ch1, 7);
    CreatList(list2, ch2, 5);
    ListNode* l1 = list1->next, * l2 = list2->next;
    while (l1) {
        if (l1->next->data == 'i')
            break;
        l1 = l1->next;
    }
    while (l2) {
        if (l2->next->data == 'i')
            break;
        l2 = l2->next;
    }
    l2->next = (l1->next);

    ListNode * ans = Search(list1, 7, list2, 5);
    cout << ans->data;
    return 0;
}